package helper

import (
	"fmt"
	"time"
)

type ScheduleHelper struct {
}

func NewScheduleHelper() *ScheduleHelper {
	return &ScheduleHelper{}
}

func (s *ScheduleHelper) Start(taskName string, duration time.Duration, f func()) {
	fmt.Println("开启任务调度器--", taskName)
	ticker2 := time.NewTicker(duration)
	f()
	go func() {
		defer func() {
			ticker2.Stop()
			fmt.Println("stop ticker success")
		}()
		for range ticker2.C {
			f()
		}
	}()

	//ticker := time.NewTicker(time.Second) defer ticker.Stop() done := make(chan bool) go func() {     time.Sleep(10 * time.Second)     done <- true }() for {     select {     case <-done:         fmt.Println("Done!")         return     case t := <-ticker.C:         fmt.Println("Current time: ", t)     } }
}
